﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using HA.ModFlow.Domain.DomainLayer;

namespace HA.ModFlow.Controls.Windows
{
    /// <summary>
    /// winGHBPack.xaml 的交互逻辑
    /// </summary>
    public partial class winGHBPack : Window
    {
        public winGHBPack(ModFlowData modflow)
        {
            InitializeComponent();
            this._modflow = modflow;

            _collection = new PCGHBCollecion(modflow.SourceSinks.GeneralHeads);


            //win.Hd += "[" + Domain.DomainLayer.UnitConverter.GetLength(ProjectSerivce.DefaultService.Project.MfData.ModelOption.Length) + "]";
            //win.Cn += "[(" + 

            this.Gridhead.Header = "水头[" + Domain.DomainLayer.UnitConverter.GetLength(modflow.ModelOption.Units.Length) + "]";
            this.Gridconduction.Header = "界面导水系数[" + Domain.DomainLayer.UnitConverter.GetLength(modflow.ModelOption.Units.Length) + "^2/" +
                Domain.DomainLayer.UnitConverter.GetTime(modflow.ModelOption.Units.Time) + "]";
            this.DataContext = _collection;


            MenuItem itemCopy = new MenuItem();
            itemCopy.Header = "复制";
            itemCopy.Command = ApplicationCommands.Copy;

            //MenuItem itemPaste2 = new MenuItem();
            //itemPaste2.Header = "粘贴";
            //itemPaste2.InputGestureText = "Ctrl+V";
            //itemPaste2.Click += new RoutedEventHandler(itemPaste2_Click);

            ContextMenu cm = new ContextMenu();
            cm.Items.Add(itemCopy);
            //cm.Items.Add(itemPaste2);          
            this.dgData.ContextMenu = cm;
        }

        ModFlowData _modflow;


       PCGHBCollecion _collection;

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            int index = this._modflow.GridData.GetIndex(this._modflow.GridData.RowsCount, this._modflow.GridData.ColsCount, this._modflow.GridData.LayersCount);

            bool b = this.rbtnID.IsChecked.Value;
            if (this._collection.CheckInputIJKorIndex(this._modflow.GridData.RowsCount, this._modflow.GridData.ColsCount, this._modflow.GridData.LayersCount, index, b))
            {

            }
            else
            {
                return;
            }
            this._collection.ConfirmData();

            this.Close();
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void btnDelAll_Click(object sender, RoutedEventArgs e)
        {
            this._collection.GHBs.Clear();
        }

        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            this._collection.CreateNew();
        }

        private void btnDel_Click(object sender, RoutedEventArgs e)
        {
            if (this.dgData.SelectedItem != null)
            {
                PCGHB pCghb = this.dgData.SelectedItem as PCGHB;

                this._collection.GHBs.Remove(pCghb);

            }

        }

        private void rbtnID_Click(object sender, RoutedEventArgs e)
        {
            this._collection.isVisibleID(this.dgData, this.rbtnID.IsChecked.Value);
        }

        private void rbtnIJK_Click(object sender, RoutedEventArgs e)
        {
            this._collection.isVisibleID(this.dgData, this.rbtnID.IsChecked.Value);
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this._collection.isVisibleID(this.dgData, this.rbtnID.IsChecked.Value);
        }

        private void dgData_LoadingRow(object sender, DataGridRowEventArgs e)
        {
            e.Row.Header = e.Row.GetIndex() + 1;
        }
    }
}
